package com.atguigu.day04;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

//线程池
public class MyThreadPoolDemo {
    public static void main(String[] args) {
        //new线程池的方法
//        ExecutorService threadPool = Executors.newFixedThreadPool(5);//固定线程池数量,是工作线程
//        ExecutorService threadPool = Executors.newSingleThreadExecutor();//一池一线程
          ExecutorService threadPool = Executors.newCachedThreadPool();
        try {
            //类似顾客，是请求线程
            for (int i = 1; i <=20; i++) {

                int finalI = i;
                threadPool.execute(()->{
                    System.out.println(Thread.currentThread().getName()+"受理第"+ finalI +"个顾客");
                });

            }
        }finally {
            threadPool.shutdown();
        }
    }
}
